﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR42Request", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR42Request))]
    public class RR42RequestSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR42Request clazz;
        
        public RR42RequestSerializer(IRR42Request clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("maakond");
            if (clazz.Maakond!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Maakond))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Maakond");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("vald");
            if (clazz.Vald!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Vald))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Vald");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("asula");
            if (clazz.Asula!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Asula))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Asula");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("tanavtalu");
            if (clazz.Tanavtalu!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tanavtalu))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tanavtalu");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("majaNumbrivahemik");
            if (clazz.MajaNumbrivahemik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MajaNumbrivahemik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : MajaNumbrivahemik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("korteriNumbrivahemik");
            if (clazz.KorteriNumbrivahemik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KorteriNumbrivahemik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KorteriNumbrivahemik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("staatus");
            if (clazz.Staatus!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "isiku_staatus");
                Writer.WriteString(clazz.Staatus.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Staatus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("isikukoodFragment");
            if (clazz.IsikukoodFragment!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikukoodFragment))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikukoodFragment");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("i_syndaastad");
            if (clazz.ISyndaastad!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ISyndaastad))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ISyndaastad");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="maakond") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>maakond");
                }
                clazz.Maakond = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maakond")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>maakond", Reader.LocalName);
            }
            if (Reader.LocalName=="vald") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>vald");
                }
                clazz.Vald = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("vald")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>vald", Reader.LocalName);
            }
            if (Reader.LocalName=="asula") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>asula");
                }
                clazz.Asula = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("asula")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>asula", Reader.LocalName);
            }
            if (Reader.LocalName=="tanavtalu") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>tanavtalu");
                }
                clazz.Tanavtalu = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tanavtalu")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>tanavtalu", Reader.LocalName);
            }
            if (Reader.LocalName=="majaNumbrivahemik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>majaNumbrivahemik");
                }
                clazz.MajaNumbrivahemik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("majaNumbrivahemik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>majaNumbrivahemik", Reader.LocalName);
            }
            if (Reader.LocalName=="korteriNumbrivahemik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>korteriNumbrivahemik");
                }
                clazz.KorteriNumbrivahemik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("korteriNumbrivahemik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>korteriNumbrivahemik", Reader.LocalName);
            }
            if (Reader.LocalName=="staatus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>staatus");
                }
                clazz.Staatus = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.IsikuStaatus(Reader.ReadElementString("staatus"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>staatus", Reader.LocalName);
            }
            if (Reader.LocalName=="isikukoodFragment") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>isikukoodFragment");
                }
                clazz.IsikukoodFragment = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isikukoodFragment")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>isikukoodFragment", Reader.LocalName);
            }
            if (Reader.LocalName=="i_syndaastad") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR42Request>i_syndaastad");
                }
                clazz.ISyndaastad = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("i_syndaastad")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR42Request>i_syndaastad", Reader.LocalName);
            }
        }
    }
}
